//
//  FeedbackRecordEntity.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/6/22.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "FeedbackRecordEntity.h"

@implementation FeedbackReplyEntity

- (void)replyRow
{
    CGFloat height = 0;
    CGSize size = [@"商户回复:" boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]} context:nil].size;
    height += (13 + size.height);
    size = [self.replyContent boundingRectWithSize:CGSizeMake(kScreenW-30-26, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]} context:nil].size;
    height += (12 + size.height + 16);
    self.rowHeight = height;
}

@end

@implementation FeedbackRecordEntity

+ (NSDictionary *)modelContainerPropertyGenericClass
{
    return @{
             @"replys": FeedbackReplyEntity.class,
             };
}

@end

@implementation FeedbackRecordResponseEntity

+ (NSDictionary *)modelContainerPropertyGenericClass
{
    return @{
             @"data": FeedbackRecordEntity.class,
             };
}

- (void)dealData
{
    NSArray *data = self.data;
    if (data.count) {
        for (FeedbackRecordEntity *recordEntity in data) {
            CGSize size = [recordEntity.content boundingRectWithSize:CGSizeMake(kScreenW-30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15]} context:nil].size;
            recordEntity.contentFrame = CGRectMake(15, 20, size.width, size.height);
            
            CGFloat y = CGRectGetMaxY(recordEntity.contentFrame) + 15;
            if (recordEntity.filePaths.count > 0) {
                y += ((recordEntity.filePaths.count - 1) / 3 + 1) * (70 + 13);
            }
            size = [recordEntity.consumerName boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]} context:nil].size;
            recordEntity.consumerNameFrame = CGRectMake(15, y, size.width, size.height);
            
            size = [recordEntity.createTime boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]} context:nil].size;
            recordEntity.createTimeFrame = CGRectMake(kScreenW-15-size.width, y, size.width, size.height);
            
            NSArray<FeedbackReplyEntity *> *replys = recordEntity.replys;
            if (replys.count) {
                CGFloat replysHeight = 0;
                for (FeedbackReplyEntity *replyEntity in replys) {
                    [replyEntity replyRow];
                    replysHeight += replyEntity.rowHeight;
                }
                y = CGRectGetMaxY(recordEntity.consumerNameFrame) + 12;
                recordEntity.replysFrame = CGRectMake(15, y, kScreenW-30, replysHeight);
                recordEntity.rowHeight = CGRectGetMaxY(recordEntity.replysFrame) + 15;
            }
            else {
                recordEntity.replysFrame = CGRectZero;
                recordEntity.rowHeight = CGRectGetMaxY(recordEntity.consumerNameFrame) + 15;
            }
            
        }
    }
}

@end
